import { ElMessage, ElMessageBox } from 'element-plus'
import { removeCustomerConsultationRecord, addHotelRecord } from '../api'
import { dialog } from '@/utils/dialog'
import AddRecord from './components/AddRecord.vue'
import ViewRecord from './components/ViewRecord.vue'

export async function removeItem({ props, _c }) {
  await ElMessageBox.confirm('是否确定删除？', '提示')
  const row = props.row || {}
  const id = row.id
  if (!id) return
  await removeCustomerConsultationRecord([id])
  ElMessage.success('操作成功')
  _c.dispatch('ListPage', 'getData')
}

export async function batchDeleteRows({ ids }) {
  if (!ids.length) return Promise.reject()
  await ElMessageBox.confirm('是否确定删除？', '提示')
  await removeCustomerConsultationRecord(ids)
  ElMessage.success('操作成功') 
}

export async function addRecord({ props, _c }) {
  const data = await dialog(AddRecord, { title: '添加记录', modalClass: 'custom-dialog' }, { id: props.row?.id })
  await addHotelRecord(data)
  ElMessage.success('操作成功')
  _c.dispatch('ListPage', 'getData')
}

export async function viewRecord({ props }) {
  dialog(ViewRecord, { title: '查看记录', modalClass: 'custom-dialog' }, { id: props.row?.id })
}